package com.inside.manage.controller;

//import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.*;
import com.deepoove.poi.data.style.BorderStyle;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;

@Controller
public class DemoController {

    private String aa = "df";

    @ResponseBody
    @RequestMapping("/helloworld")
    public Object helloworld () throws IOException {







        XWPFTemplate template = XWPFTemplate.compile("D:/template.docx").render(new HashMap<String, Object>(){{
            put("title", "Poi-tl 模板引擎");
            put("name", "Poi-tl 模板引擎321321321");
            RowRenderData row0 = Rows.of("姓名", "学历").textColor("FFFFFF")
                    .bgColor("4472C4").center().create();
            RowRenderData row1 = Rows.create("李四", "博士");
            put("table1", Tables.create(row0, row1));
            put("list", Numberings.create("第一行",
                    "第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行第二行",
                    "第三行"));
            put("table0", Tables.of(new String[][] {
                    new String[] { "00", "01" },
                    new String[] { "10", "11" }
            }).border(BorderStyle.DEFAULT).create());


            ChartMultiSeriesRenderData chart = Charts
                    .ofMultiSeries("我是一个柱状图", new String[] { "张三", "李四" })
                    .addSeries("苹果", new Double[] { 15.0, 6.0 })
                    .addSeries("香蕉", new Double[] { 223.0, 119.0 })
                    .create();
            put("barChart", chart);


            ChartSingleSeriesRenderData pie = Charts
                    .ofSingleSeries("我是一个饼图", new String[] { "美国", "中国" })
                    .series("countries", new Integer[] { 35, 65 })
                    .create();

            put("pieChart", pie);

        }});
        FileOutputStream out = new FileOutputStream("D:/out_template.docx");
        template.write(out);
        out.flush();
        out.close();
        template.close();

        return "你好啊世界"+ aa;
    }
}
